#include <windows.h>
#include "keypad.h"
#include "log.h"
#include <stdio.h>
static KEYPAD_CALLBACK s_keypad_callback = 0;
int platform_setup_m_keys(int rowMark,int colMark,KEYPAD_CALLBACK cb){
    debugf("platform_setup_m_keys");
    s_keypad_callback = cb;
    return 0;
}
static HHOOK g_Hook;
static BOOL g_keypress = FALSE;
LRESULT CALLBACK KeyboardProc(int code,WPARAM w,LPARAM l)
{
    PKBDLLHOOKSTRUCT pKeyboardHookStruct =  (PKBDLLHOOKSTRUCT)l;
	switch(pKeyboardHookStruct->scanCode){
        case 16/*q*/:{
            debugf("QUIT");
            PostMessage(NULL,WM_QUIT,0,0);
        }break;
        case 20 /*t*/:{
            if(s_keypad_callback){
                if(w == WM_KEYDOWN){
                    if(g_keypress){
                        break;
                    }
                    g_keypress = TRUE;
                }else{
                    g_keypress = FALSE;
                }
                s_keypad_callback(KEYPAD_TYPE_MATRIX,255,255,w == WM_KEYDOWN);
            }
        }break;
    }
    return TRUE;
}
int platform_keypad_init(){
    char c = 0;
    if(g_Hook){
        return 0;
    }
	g_Hook = SetWindowsHookEx(WH_KEYBOARD_LL,KeyboardProc,GetModuleHandle(NULL),0);
    return 0;
}
int platform_keypad_uninit(){
    if(g_Hook){
        UnhookWindowsHookEx(g_Hook);
        g_Hook = 0;
    }
}
int platform_setup_gpio_keys(int rowMark,int colMark,E_GPIOKEY_MODE mode,KEYPAD_CALLBACK cb){
    return 0;
}
